/*
 * JSA Example
 *
 * @package jsa
 * @author sheiko
 * @version jquery.jsa.js, v 2.0
 * @license MIT
 * @copyright (c) Dmitry Sheiko http://www.dsheiko.com
 * Code style: http://docs.jquery.com/JQuery_Core_Style_Guidelines
 */
// Local scope
(function( $, jsa ) {
    "use strict";
    // Namespace constants
    var PAGE_TITLE_PREF = 'JS Application Design : ';
    // Application scope
    var App = (function() {
        // Application event handlers
        var _handler = {
            introOnChange: function( e, node ) {
                document.title = PAGE_TITLE_PREF + $( node ).attr( 'title' );
            }
        };
        return {
            init : function() {
                App.syncUI();
                // Invoke the first instance of Intro
                App.Intro.createInstance({
                    boundingBox: $('div.intro')
                });
            },
            syncUI : function() {
                // Application subscribes for a custom event
                $(document).bind( 'intro-onchange', _handler.introOnChange );
            }
        }
    }());
    //  Module
    App.Intro = function( settings ) {
        // Module constants
        var MYCONSTANT = null,
        // Private properties
        _a = null,
        _b = null,
        // event handlers
        _handler = {
            onclick : function(e) {
                // e.data is 'this' context of the module
                e.data.node.boundingBox.attr('data-pattern', $(this).data('id'));
                // Example of communication module to module, module to application
                $(document).trigger( 'intro-onchange', [this]);
            }
        };
        return {
            __extends__ : jsa.WidgetAbstract,
            HTML_PARSER : {
                toolbar : 'div.toolbar'
            },
            init : function() {
            },
            renderUI : function() {
            },
            syncUI : function() {
                this.node.toolbar.find( 'li' ).bind( 'click.intro', this, _handler.onclick );
            }
        };
    };


    // Document is ready
    $(document).bind( 'ready.app', App.init );

})( jQuery, jsa );

